package com.edu.app.controller.core;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping(value = "/api/performance")
@RestController
public class SysPerformanceController {

    /*@Autowired
    private SysPerformanceService sysPerformanceService;

    @Autowired
    private SysTargetService sysTargetService;

    @Autowired
    private SysUserService sysUserService;

    @Autowired
    private SysUserRoleService sysUserRoleService;

    @PostMapping(value="")
    public ModelMap addPerformance(@RequestHeader("Authorization") String token, @RequestBody SysPerformance sysPerformance) {
        try{
            String username = JWTUtil.getUsername(token);
            sysPerformance.initializeSystemColumns(username);
            Integer i = sysPerformanceService.add(sysPerformance);
            if(i > 0 ){
                return MsgUtil.retMsg(SysMessage.ADD_PERFORMANCE_SUCCEED, "performance", sysPerformance);
            }
            else{
                return ErrorUtil.retErrMsg(ErrorConstant.SERVER_INTERNAL_ERROR);
            }
        }catch (exception e){
            return ErrorUtil.retErrMsg(e);
        }
    }

    @PostMapping(value="/addTarget")
    public ModelMap addTarget(@RequestHeader("Authorization") String token, @RequestBody SysTarget sysTarget) {
        try{
            String username = JWTUtil.getUsername(token);
            sysTarget.initializeSystemColumns(username);
            Integer i = sysTargetService.add(sysTarget);
            if(i > 0 ){
                return MsgUtil.retMsg(SysMessage.ADD_TARGET_SUCCEED, "target", sysTarget);
            }
            else{
                return ErrorUtil.retErrMsg(ErrorConstant.SERVER_INTERNAL_ERROR);
            }
        }catch (exception e){
            return ErrorUtil.retErrMsg(e);
        }
    }

    /*@GetMapping(value="/performance")
    public ModelMap getPerformance(@RequestHeader("Authorization") String token){
        try{
            String username = JWTUtil.getUsername(token);
            return ErrorUtil.retErrMsg(e);

        }catch (exception e){
            return ErrorUtil.retErrMsg(e);
        }
    }*/

    /*@PostMapping(value="")
    public ModelMap addWinPerformance(@RequestHeader("Authorization") String token, @RequestBody SysPerformance sysPerformance){

        try{
            String username = JWTUtil.getUsername(token);
            Integer user_id = sysPerformance.getUser_id();
            SysUser sysUser = sysUserService.getObjectById(user_id);
            if(sysUser != null){
                if(username.equalsIgnoreCase(sysUser.getUsername())){
                    //add userself performance
                    sysPerformanceService.add(sysPerformance);
                    return MsgUtil.retMsg(SysMessage.ADD_PERFORMANCE_SUCCEED, null, null);
                }else if(sysUserRoleService.getRoleListByUserId(sysUser.getId()).contains(StaticConstant.ADMIN_ROLE)){
                    //Admin to add each person's performance
                    return MsgUtil.retMsg(SysMessage.ADD_PERFORMANCE_SUCCEED, null, null);
                }else{
                    return ErrorUtil.retErrMsg(ErrorConstant.SERVER_INTERNAL_ERROR);
                }
            }else{
                return ErrorUtil.retErrMsg(ErrorConstant.SERVER_INTERNAL_ERROR);
            }
        }catch (exception e){
            return ErrorUtil.retErrMsg(e);
        }
    }*/

    /*
    @GetMapping(value = "/week")
    public ModelMap getPerformanceByWeek (){

    }

    @GetMapping(value = "/month")
    public ModelMap getPerformanceByMonth (){

    }

    @GetMapping(value = "/year")
    public ModelMap getPerformanceByYear (){

    }*/

}
